package com.lwc.cfdns.pojo.security;

import com.lwc.cfdns.enums.ResultCode;
import com.lwc.cfdns.utils.ServletUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 认证失败处理器
 *
 * @author luwc
 * @title AuthenticationEntryPointImpl
 * @description
 * @time 2023/5/16 09:11:06
 * @version: 1.0
 */
@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        ServletUtils.renderString(response, ResultCode.AUTH_UNAUTHORIZED);
    }
}
